﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestByWire.Tutorial.Domain;

namespace TestByWire.Tutorial
{
	using System;

	[TestClass]
	[UseStubLateBound(typeof(ICalculationEngine), "_summaryCalculator")]
	[UseStubLateBound(typeof(ICalculationEngine), "_anotherCalculator")]
	public class Events : TestTarget<LegacyCode>
	{
		[TestMethod]
		public void SummaryCalculatorCalculationComplete_MustBeRaised_WhenSummaryCalculationEngineCompletes()
		{
			Scenario.Is(ClassIsInitialized);

			When<ICalculationEngine>.RaiseEvent("_summaryCalculator", x => x.CalculationComplete += null, this);

			Then.TargetFulfills(x => x.FirstCalculationResult == 10);
		}

		[TestMethod]
		public void AnotherCalculatorCalculationComplete_MustBeRaised_WhenAnotherCalculationEngineCompletes()
		{
			Scenario.Is(ClassIsInitialized);

			When<ICalculationEngine>.RaiseEvent("_anotherCalculator", x => x.CalculationComplete += null, this);

			Then.TargetFulfills(x => x.SecondCalculationResult == 20);
		}

		private void ClassIsInitialized()
		{
			When.Calling.Intialize();
		}
	}
}
